package net.zjitc.controller;

import net.zjitc.pojo.Cart;
import net.zjitc.pojo.User;
import net.zjitc.service.CartService;
import net.zjitc.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @Author admin
 * @Date 2019/5/29 10:52
 */
@Controller
    @RequestMapping("/cart")
public class Cartcontroller {
@Autowired
CartService cartService;
@Autowired
UserService userService;
@RequestMapping("/findByCart")
    public String findByCart(Model model, HttpServletRequest request,HttpSession session){
    //将用户购物车内容显示到页面上
    String login = (String) request.getSession().getAttribute("login");
    User user = new User();
    user.setUsername(login);
    User byname = userService.findByname(login);
    List<Cart> byCart = cartService.findByCart(byname.getId());
    model.addAttribute("cart",byCart);
    session.setAttribute("CART",byCart);
    if (byCart.size()!=0){
        model.addAttribute("suss1","有购买记录");
    }


    //因为不太会用ajax所以先加载这个页面在跳转方法
    return "/client/index";
    }
}
